package com.alavente.service;

import java.util.Date;
import java.util.List;

import com.alavente.dao.GenericDAOInterface;
import com.alavente.dao.HibernateAchatDAO;
import com.alavente.objects.Achat;

public class AchatManager {
	
	GenericDAOInterface<Achat> daoAchat = new HibernateAchatDAO();
	
	/**
	 * Acheter un objet
	 * @param achat
	 * @return
	 */
	public Achat createAchat(Achat achat) {
		
		achat.setDateAchat(new Date());
		
		if (daoAchat.create(achat))
			return achat;
		else
			return null;
	}
	
	/**
	 * Noter un achat
	 * @param achat
	 * @return
	 */
	public Achat updateAchat(Achat achat) {
		
		if (daoAchat.update(achat))
			return achat;
		else
			return null;
	}
	
	/**
	 * Obtient les achats d'un client
	 * @param numClient
	 * @return
	 */
	public List<Achat> getAchatsClient(int numClient) {
		
		return ((HibernateAchatDAO)daoAchat).getAchatsClient(numClient);
	}
	
	/**
	 * Obtient un achat particulier d'un client
	 * @param numDemande
	 * @param numClient
	 * @return
	 */
	public Achat getAchat(int numDemande, int numClient) {
		
		return ((HibernateAchatDAO)daoAchat).getAchat(numDemande, numClient);
	}
}
